from django.db import models

# Create your models here.
class Student(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    email = models.EmailField(max_length=100)
    phone = models.CharField(max_length=100)
    STATUS_CHOICES = (
        (0, '未入学'),
        (1, '已入学'),
        (2, '已毕业'),
    )
    status = models.IntegerField(choices=STATUS_CHOICES, default=0)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)


# 关联表
class StudentCourse(models.Model):
    """学生-课程 多对多 关联表"""
    student_id = models.PositiveIntegerField()
    course_id  = models.PositiveIntegerField()

    class Meta:
        db_table = 'stu_course'
        unique_together = ('student_id', 'course_id')   # 防重复选课
        indexes = [
            models.Index(fields=['student_id']),
            models.Index(fields=['course_id']),
        ]

class CourseTeacher(models.Model):
    """课程-老师 一对多 关联表（一门课只能一个老师）"""
    course_id  = models.PositiveIntegerField(unique=True)   # 一门课只出现一次
    teacher_id = models.PositiveIntegerField()

    class Meta:
        db_table = 'course_teacher'
        indexes = [
            models.Index(fields=['course_id']),
            models.Index(fields=['teacher_id']),
        ]